/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
int ans;
int a[10];
class Solution {
public:
    bool check(const vector<int>& cnt) {
        int ans = 0;
        for (auto x : cnt) {
            if (x & 1)ans++;
        }
        return ans <= 1;
    }
    int dfs(TreeNode* root, vector<int>& cnt) {
        if (!root)return 0;
        int ans = 0;
        cnt[root->val]++;
        if (root->left == nullptr && root->right == nullptr) {
            if (check(cnt))ans = 1;
        }
        else {
            ans += dfs(root->left, cnt);
            ans += dfs(root->right, cnt);
        }
        cnt[root->val]++;
        return ans;
    }
    int pseudoPalindromicPaths(TreeNode* root) {
        vector<int>cnt(10);
        return dfs(root, cnt);
    }
};